 <!DOCTYPE html>
<html>

<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    

    <title>{$Think.config.site.title} - 采购管理</title>

    <meta name="keywords" content="{$Think.config.site.keywords}">

    <link href="{$Think.config.site.resource_url}css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/animate.min.css" rel="stylesheet">
    <link href="{$Think.config.site.resource_url}css/style.min.css?v=4.0.0" rel="stylesheet">

</head>
<style>
#listtable .fa{
	cursor:pointer;
	color:#1ab394;
	margin-right:1em;
}
th .tag{font-size: 12px; color: #e66c6c; font-weight: normal;}
.ibox-title .tag{font-size: 12px; color: #e66c6c; font-weight: normal; display: inline-block; margin-left: 20px;}
.specval-hide{display: none;}
</style>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
      <div class="row">
            <div class="col-sm-4">
                <div id="nestable-menu">
                	<button type="button" data-action="allot" class="btn btn-primary btn-sm"><i class="fa fa-share-alt"></i> 分配</button>
                </div>
            </div>
      </div>
      <div class="row">
          <div class="col-sm-12">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <h5>待分配商品列表</h5>
                        <!-- <span class="tag">说明：</span> -->
                    </div>
                    <div class="ibox-content">
                        <div class="row">
                        	<div class="col-sm-6">
                        	</div>
                          	<div class="col-sm-6">
                                <div class="input-group pull-right">
                                <form action="{:url('index')}" method="get" enctype="application/x-www-form-urlencoded">
                                <div class="input-group">
                                    <input type="text" placeholder="请输入关键词" class="input-sm form-control" value="{$Think.get.keywords ?? ''}" name="keywords">
                                    <span class="input-group-btn">
                                        <button type="submit" class="btn btn-sm btn-primary"> 搜索</button> </span>
                                </div>
                                </form>
                                </div>
                            </div>
                            
                        </div>
                        <div class="table-responsive">
                            <table class="table table-striped" id="listtable">
                                <thead>
                                    <tr>
                                        <th width="30"><input name="checkall" id="checkall"  type="checkbox" class="i-checks" value="1"></th>
                                        <th width="100">商品图片</th>
                                        <th width="">商品名称</th>
                                        <th width="150">已有库存数量</th>
                                        <th width="150">采购数量</th>
                                        <th width="150">商品品牌</th>
                                        <th width="150">当前售价</th>
                                        <th width="150">上次采购价格</th>
                                        <!-- <th width="150">供应商</th> -->
                                        <!-- <th width="150">操作</th> -->
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr style="background: #e6afaf;color: #ffffff;"><td colspan='8'>无供应商商品</td></tr>
                                	{volist name="list['purchase']" id="vo"}
                                    <tr data-id="{$vo.goods_id}" data-specval_id="{$vo.specval_id}">
                                        <td>
                                            <input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.goods_id}">
                                        </td>
                                        <td><img src="{$vo.picture}" style="max-height: 60px; max-width: 60px"></td>
                                        <td class="goodsname">（{$vo.brand_name}）{$vo.goods_name}&nbsp;&nbsp;[&nbsp;1*{$vo.spec_name}&nbsp;({$vo.specval_name})&nbsp;]</td>
                                        <td>{if($vo.stock_num)} {$vo.stock_num}{$vo.spec_name} {else} 0 {/if}</td>
                                        <td>{$vo['stock']*-1}{$vo.spec_name}</td>
                                        <td>{if($vo.brand_name)}{$vo.brand_name}{else}---{/if}</td>
                                        <td>{$vo.price}</td>
                                        <td>{if($vo.purchase_price)}{$vo.purchase_price}{else}---{/if}</td>
                                        <!-- <td>{$vo.supplier_name}</td> -->
                                        <!-- <td>
                                        	<a href="{:url('editGoods',['goods_id'=>$vo['goods_id']])}" class="fa fa-edit"> 分配</a>
                                        </td> -->
                                    </tr>
                                   {/volist}
                                   <tr style="background: #e6afaf;color: #ffffff;"><td colspan='8'>供应商取消或缺货商品</td></tr>
                                   {volist name="list['supplier']" id="vo"}
                                    <tr data-id="{$vo.goods_id}" data-specval_id="{$vo.goods_specval_id}">
                                        <td>
                                            <input name="ids[]"  type="checkbox" class="i-checks" value="{$vo.goods_id}">
                                        </td>
                                        <td><img src="{$vo.picture}" style="max-height: 60px; max-width: 60px"></td>
                                        <td class="goodsname">（{$vo.brand_name}）{$vo.goods_name}&nbsp;&nbsp;[&nbsp;1*{$vo.goods_spec_name}&nbsp;({$vo.goods_specval_name})&nbsp;]</td>
                                        <td>---</td>
                                        <td>{$vo['num']}{$vo.goods_spec_name}</td>
                                        <td>{if($vo.brand_name)}{$vo.brand_name}{else}---{/if}</td>
                                        <td>{$vo.price}</td>
                                        <td>---</td>
                                    </tr>
                                   {/volist}

                                </tbody>
                            </table>
                        </div>

                    </div>
                </div>
            </div>

        </div>
    </div>

    <script src="{$Think.config.site.resource_url}js/jquery.min.js?v=2.1.4"></script>
    <script src="{$Think.config.site.resource_url}js/bootstrap.min.js?v=3.3.5"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/peity/jquery.peity.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/iCheck/icheck.min.js"></script>
    <script src="{$Think.config.site.resource_url}js/plugins/layer/layer.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/majax.js"></script>
    <script src="{$Think.config.site.common_resource_url}js/jedit.js"></script>
</body>

</html>
<script>

var layer_font='';
$(document).ready(function() {
	
	$(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

	//全选
	$("#checkall").bind("ifChecked",function(){
		$("input[name='ids[]']").iCheck("check");
	});
	//取消全选
	$("#checkall").bind("ifUnchecked",function(){
		$("input[name='ids[]']").iCheck("uncheck");
	});
	//顶部按钮
    $("#nestable-menu").on("click",
    function(e) {
        var target = $(e.target),
        action = target.data("action");

		//保存排序
        if (action === "allot") {
            var list = [],goods='';
			$("input[name='ids[]']:checked").each(function(index, element) {
				list.push($(this).closest("tr").data("specval_id"));
				
			});
			if(list.length < 1) {
				layer.msg('请至少选中一项', {icon: 5});
				return false;
			}
			
			layer_font = layer.open({
				type: 2,
				title: '选择采购员',
				shadeClose: true,
				shade: 0.8,
				area: ['900px', '90%'],
				content: '{:url("allot")}', //iframe的url
				btn: ['确定', '取消'],
				btn1: function(index, layero){
					var d = $('iframe',layero)[0].contentDocument;
					var uid = $("input[name='uid']:checked",d).val();
					if(uid == undefined) {
						layer.msg('未选择配送员', {icon: 2});
						layer.close(index);
						return false;
					}
					specval_id = list.join(',');
					majax('{:url("allot")}',{uid:uid,specval_id:specval_id},function(d){
						if (d.code<=0) {
							layer.msg(d.msg, {icon: 5});
							layer.close(index);
						}else{
                            layer.close(index);
                            wprint(d.data.PurchaseId);
                        }
					})
				}
		  	});
        }

    });

    
});	

function wprint(id){
    layer_font = layer.open({
        type: 2,
        title: '打印',
        shadeClose: true,
        shade: 0.8,
        area: ['900px', '90%'],
        end: function(){window.location.reload(true)},
        content: '{:url("webPrint")}?ids='+id, //iframe的url
    });
}
function closeIfram(){
    layer.close(layer_font);
}
</script>